mui.init();
		var doc = document;
		var userinfo = app.getState() || {};
		var uid = userinfo.user_id;
        var addr_id;
        
        window.onload = function(){
        	
        	mui.plusReady(function(){
			    //关闭等待框
			    plus.nativeUI.closeWaiting();
			    //显示当前页面
			    mui.currentWebview.show();
			    
			    addr_id=plus.webview.currentWebview().addr_id;
			    
			    mui.ajax({
					url: apiurl + "User/address_info/",
					data: {'address_id':addr_id,'_token':userinfo.token},
					async: true,
					dataType: 'json',
					crossDomain: true, //强制使用5+跨域
					type: 'post',
					timeout: 10000,
					success: function(res) {
						console.log(JSON.stringify(res));
						if(res.status ==-3){
							mui.toast(res.msg);
							app.out();
							return false;
						} else {
							// 请求成功
							document.getElementById('username').value=res.data.username;
							document.getElementById('mobile').value=res.data.mobile;
							document.getElementById('showCityPicker3').value=res.data.addrdesc;
							document.getElementById('address').value=res.data.address;
					
							if(res.data.is_default==1){
								document.getElementById('is_default').className="mui-switch mui-active";
							}
							else{
								document.getElementById('is_default').className="mui-switch";
							}
						}

					},
					error: function(xhr, type, errorThrown) {
						//console.log(JSON.stringify(xhr));
						//console.log(JSON.stringify(type));
						//console.log(JSON.stringify(errorThrown));
						mui.toast('操作失败！');
					}
				});
			    
		  });
			
        }
        
       
       
        document.getElementById('set_btn').addEventListener('tap', function() {
			var addrdata = {
				user_id: uid,
				address_id: addr_id,
				username: document.getElementById('username').value.trim(),
				addrdesc: document.getElementById('showCityPicker3').value,
				address: document.getElementById('address').value.trim(),
				mobile: document.getElementById('mobile').value.trim(),
				_token:userinfo.token
			};
			
			if(addrdata.username == '') {
				mui.toast('收货人姓名不能为空');
				return;
			}
			if(addrdata.mobile == '') {
				mui.toast('电话不能为空');
				return;
			}
			if(addrdata.addrdesc == '') {
				mui.toast('省市区不能为空');
				return;
			}
			
			if(addrdata.address == '') {
				mui.toast('详细地址不能为空');
				return;
			}
			
			if(document.getElementById('is_default').className=='mui-switch mui-active'){
				addrdata.is_default=1;
			}else{
				addrdata.is_default=0;
			}
           
			mui.post(apiurl + "User/set_address/", addrdata, function(rest) {
				if(rest.status ==-3){
					mui.toast(rest.msg);
					app.out();
					return false;
				}
				
				if(rest.status && rest.status > 0) {
					mui.toast(rest.msg);
					//mui.fire(plus.webview.getWebviewById('buyin.html'), 'refresh_data');
					mui.fire(plus.webview.getWebviewById('address.html'), 'refresh_data');
					mui.fire(plus.webview.getWebviewById('select_address.html'), 'refresh_data');
					mui.fire(plus.webview.getWebviewById('order.html'), 'refresh_address',{
						'address_id':rest.data.address_id,
						'username':rest.data.username,
						'addrdesc':rest.data.addrdesc,
						'address':rest.data.address,
						'mobile':rest.data.mobile
					});
					
					mui.back();
				} else {
					mui.toast(rest.msg);
				}
			
			});
				
		});
		
		
		
		//级联示例
		var cityPicker3 = new mui.PopPicker({
			layer: 3
		});
		cityPicker3.setData(cityData3);
		var showCityPickerButton = document.querySelector('#address-data #showCityPicker3');
		showCityPickerButton.addEventListener('tap', function(event) {
			document.getElementById('username').blur();
			document.getElementById('mobile').blur();
			cityPicker3.show(function(items) {
				showCityPickerButton.value = (items[0] || {}).text + " " + (items[1] || {}).text + " " + (items[2] || {}).text;
				//返回 false 可以阻止选择框的关闭
				//return false;
			});
		}, false);
		
		
		